import { baseURL, request } from "../config/axios.config";

const dashboard = async () => {
  return request.get("/admin/dashboard");
};

const listUsers = async (page) => {
  return request.get("/admin/listUsers", {
    params: page,
  });
};

const updateUser = async (user) => {
  return request.post("/admin/updateUser", user);
};

const deleteUser = async (id) => {
  return request.get(`/admin/deleteUser/${id}`);
};

const listTags = async (page, createTime) => {
  if (page) {
    page.fromTime = null;
    page.endTime = null;
  }
  if (createTime) {
    page.fromTime = createTime[0];
    page.endTime = createTime[1];
  }
  return request.get("/admin/listTags", {
    params: page,
  });
};

const updateTag = async (tag) => {
  return request.post("/admin/updateTag", tag);
};

const deleteTag = async (id) => {
  return request.get(`/admin/deleteTag/${id}`);
};
const addTag = async (tag) => {
  return request.post("/admin/addTag", tag);
};

const listPosts = async (page) => {
  return request.get("/admin/listPosts", { params: page });
};
const updatePost = async (post) => {
  return request.post("/admin/updatePost", post);
};
const deletePost = async (id) => {
  return request.get(`/admin/deletePost/${id}`);
};

const listConfig = async (page, createTime) => {
  if (page) {
    page.fromTime = null;
    page.endTime = null;
  }
  if (createTime) {
    page.fromTime = createTime[0];
    page.endTime = createTime[1];
  }
  return request.get(`/admin/listConfig`, { params: page });
};
const updateConfig = async (config) => {
  return request.post("/admin/updateConfig", config);
};
const uploadURL = baseURL + "/admin/uploadTagAvatar";

export {
  dashboard,
  listUsers,
  updateUser,
  deleteUser,
  listTags,
  updateTag,
  deleteTag,
  addTag,
  listPosts,
  updatePost,
  deletePost,
  listConfig,
  updateConfig,
  uploadURL,
};
